import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:墨琦
 * Data:2023-03-21
 * Time:14:02
 */
public  class Text implements ActionListener {
    JButton fw1;JFrame kk;
    int x=0,y=0;
    int i=0;
    public static void main(String[] args) {
        Text fw=new Text();
        fw.go();
    }
    public void go()
    {
     kk=new JFrame();
     kk.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

     fw1=new JButton("开始游戏");

     fw1.addActionListener(this);
     text1 fw2=new text1();
     kk.getContentPane().add(BorderLayout.CENTER,fw2);
     kk.getContentPane().add(BorderLayout.SOUTH,fw1);
     kk.setSize(500,600);
     kk.setVisible(true);
     while(true)
    {
        kk.repaint();
        if(x==500)
        {
            x=0;
            y=0;
        }
        try{
            Thread.sleep(20);
        }catch(Exception ee){
        }
        x++;y++;
    }
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        fw1.setText("游戏结束");

    }
    class text1 extends JPanel
    {
        public void paintComponent(Graphics g)
        {
            g.setColor(Color.green);
            g.fillRect(0,0,this.getWidth(),this.getHeight());
            g.setColor(Color.red);
            g.fillOval(x,y,40,40);
        }
    }
}
